﻿
using Abp.Application.Services.Dto;
using Abp.Web.Models;
using Abp.Web.Mvc.Authorization;
using KDS.Mes.Mes.Atlas;
using KDS.Mes.Mes.Atlas.Dtos;
using KDS.Mes.Web.Models.Atlass;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace KDS.Mes.Web.Controllers
{
    public class AtlassController : MesControllerBase
    {

        private readonly IAtlasAppService _atlasAppService;

        public AtlassController(IAtlasAppService atlasAppService)
        {
            _atlasAppService = atlasAppService;
           
        }

        public  ActionResult Index()
        {
            var lines = new List<ComboboxItemDto>();
            lines.Insert(0, new ComboboxItemDto("", ""));
            lines.Insert(1, new ComboboxItemDto("X001", "一线"));
            lines.Insert(2, new ComboboxItemDto("X002", "二线"));
            lines.Insert(3, new ComboboxItemDto("X003", "三线"));

            var statinNos = new List<ComboboxItemDto>();
            statinNos.Insert(0, new ComboboxItemDto("", ""));
            statinNos.Insert(1, new ComboboxItemDto("S04", "S04"));
            statinNos.Insert(2, new ComboboxItemDto("S041", "S041"));
            statinNos.Insert(3, new ComboboxItemDto("S042", "S042"));
            statinNos.Insert(3, new ComboboxItemDto("S05", "S05"));
            statinNos.Insert(3, new ComboboxItemDto("S08", "S08"));
            statinNos.Insert(3, new ComboboxItemDto("S081", "S081"));
            statinNos.Insert(3, new ComboboxItemDto("S082", "S082"));
            statinNos.Insert(3, new ComboboxItemDto("S131", "S131"));
            statinNos.Insert(3, new ComboboxItemDto("S132", "S132"));

            var model = new AtlassViewModel
            {
                FilterText = Request.QueryString["filterText"],
                Lines = lines,
                StationNos=statinNos
            };
            return View(model);
        }

        [DontWrapResult]
        public JsonResult GetAllAtlass(int limit, int offset, string sortName, string sortOrder,
                                       string lineId, string stationNoId, string seatID, DateTime? time1, DateTime? time2)
        {
            var sort = !string.IsNullOrEmpty(sortName) ? string.Format("{0} {1}", sortName, sortOrder) : "";
            var filter = new GetAtlasInput
            {
                SkipCount = offset,
                MaxResultCount = limit,
                Sorting = sort,
                LineId = lineId,
                StationNoId=stationNoId,
                SeatID = seatID,
                Time1 = time1,
                Time2 = time2,
            };
            var pagedTasks = _atlasAppService.GetPagedAtlass(filter);
            return Json(new { total = pagedTasks.TotalCount, rows = pagedTasks.Items }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        //[AbpMvcAuthorize(AtlasAppPermissions.Atlas_CreateAtlas,AtlasAppPermissions.Atlas_EditAtlas)]
        public async Task<PartialViewResult> CreateOrEditAtlasModal(int? id)
        {
		var input=new NullableIdDto<int>{Id=id};
	 
                 var output=    await _atlasAppService.GetAtlasForEditAsync(input);

				 var viewModel=new CreateOrEditAtlasModalViewModel(output);


            return PartialView("_CreateOrEditAtlasModal",viewModel);
        }
	 
       
    }
}